package gulimall.controller;

import gulimall.domain.bo.SearchParamBo;
import gulimall.domain.vo.SearchResultVo;
import gulimall.service.SearchService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author HLF
 * @date 2022/7/9 18:18
 */
@Controller
@RequiredArgsConstructor
public class SearchController {
    private final SearchService searchService;


    /**
     * 首页检索请求
     *
     * @param paramBo 检索参数
     * @param model
     * @return
     */
    @GetMapping(value = {"/list.html", "/"})
    public String listPage(SearchParamBo paramBo, Model model) {
        SearchResultVo resultVo = searchService.search(paramBo);
        model.addAttribute("result", resultVo);
        return "list";
    }

    @ResponseBody
    @GetMapping(value = {"/result"})
    public SearchResultVo result(SearchParamBo paramBo, Model model) {
        SearchResultVo resultVo = searchService.search(paramBo);
        return resultVo;
    }

}
